﻿@model TWCRM.Models.Home.ProductTypeModel
@{
    Layout = "/Views/Shared/_SubLayout.cshtml";
    ViewBag.Title = "產品類別";
}
<script>
    var isNew = true;
    $(document).ready(function () {
        isNew = $.url().param('id') == undefined;

        if (isNew)
            $('.metro_input_contain input:first').focus();

        $.fn.metro.onPrevClick = function () {
            window.history.go(-1);
        };

        adjustMetroInputContain();
    });
</script>
<div id="ProductTypeEdit">
    @using (Html.BeginForm())
    {
        @Html.HiddenFor(m => m.ID)
        @Html.HiddenFor(m => m.IsNew)
        @Html.HiddenFor(m => m.ParentID)
        <div class="metro_toolbar">
            <div class="metro_input_contain">
                <a class="metro_input_btn" onclick="confirm()">儲存類別</a>
            </div>
        </div>
        if (Model.ParentID != null)
        {
        <div class="metro_input_contain">
            <label for="Parent" class="metro_input_caption">
                上級類別
            </label>
            <label class="metro_input_display one_line">@Model.Parent</label>
        </div>
        }
        <div class="metro_input_contain">
            <label for="Name" class="metro_input_caption">
                類別名稱
            </label>
            @Html.TextBoxFor(m => m.Name, new { @class = "metro_input_textinput one_line"})
        </div>
    }
</div>
<script>
    function confirm() {
        if (!valEmpty($("#Name"))) {
            showError("類別名稱是必要欄位不可留白");
            return;
        }

        showLoading();
        $('form').submit();
    }

    function adjustMetroInputContain() {
        var maxCaptionWidth = $.fn.calcMaxWidth($('.metro_input_caption'));
        $('.metro_input_caption').each(function () {
            $(this).width(maxCaptionWidth);
        });
    }
</script>
